package com.mininglamp.hbga.util;

import java.util.List;
import java.util.Map;

import com.mininglamp.hbga.util.response.ErrorResponse;
import com.mininglamp.hbga.util.response.ListObjResponse;
import com.mininglamp.hbga.util.response.MapResponse;
import com.mininglamp.hbga.util.response.OkResponse;
import com.mininglamp.hbga.util.response.PageResponse;
import com.mininglamp.hbga.util.response.Response;
import com.mininglamp.hbga.util.response.SingleObjResponse;

public class ResponseHelper {

    public static final String OK = "200";
    public static final String ERROR = "300";
    public static final String RE_LOGIN = "301";
    public static final String NOT_FOUND = "404";
    public static final String REASON = "请重新登录.";

    public static Response OK() {
        Response response = new Response() {
        };
        response.setStatusCode(OK);
        return response;
    }

    public static Response OK(Response response) {
        response.setStatusCode(OK);
        return response;
    }

    public static Response OK(String message) {
        OkResponse response = new OkResponse();
        response.setStatusCode(OK);
        response.setMessage(message);
        return response;
    }

    public static Response Error(String reason) {
        return Error(ERROR, reason);
    }

    public static Response Error(String statusCode, String reason) {
        ErrorResponse errorResponse = new ErrorResponse();
        errorResponse.setStatusCode(statusCode);
        errorResponse.setMessage(reason);
        return errorResponse;
    }

    public static Response Relogin() {
        return Error(RE_LOGIN, REASON);
    }

    public static Response NotFound() {
        return Error(NOT_FOUND, "");
    }

    public static Response objResponse(Object obj) {
        SingleObjResponse<Object> response = new SingleObjResponse<>();
        response.setObj(obj);
        return OK(response);
    }

    public static <T> Response listObjResponse(List<T> listObj) {
        ListObjResponse<T> response = new ListObjResponse<>();
        response.setListObj(listObj);
        return OK(response);
    }

    public static <K, V> Response mapResponse(Map<K, V> map) {
        MapResponse<K, V> response = new MapResponse<>();
        response.setMap(map);
        return OK(response);
    }

    public static <T> Response pageResponse(long totalCount, int pageNo, int pageSize, List<T> objList) {
        PageResponse<T> response = new PageResponse<T>();
        response.setTotalCount(totalCount);
        response.setPageNo(pageNo);
        response.setPageSize(pageSize);
        response.setBodyData(objList);
        return OK(response);
    }

}
